<!DOCTYPE html>
<html>
  <head>
        <title>生活必需品囤货清单</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
        <link rel="stylesheet" href="https://cdn.staticfile.org/minireset.css/0.0.2/minireset.css">
        <link rel="stylesheet" href="https://at.alicdn.com/t/font_1534407_mj4m6393aya.css">
        <script src="https://cdn.staticfile.org/promise-polyfill/8.2.0/polyfill.min.js"></script>
        <script src="https://cdn.staticfile.org/jquery/2.2.4/jquery.min.js"></script>
        <script src="https://cdn.staticfile.org/vue/3.0.11/vue.global.js"></script>
        <script src="https://cdn.staticfile.org/vant/3.2.4/vant.min.js"></script>
        <link href="https://cdn.staticfile.org/vant/3.2.4/index.min.css" rel="stylesheet"><!--pc端click代替touch-->
        <script src="https://cdn.jsdelivr.net/npm/@vant/touch-emulator"></script>
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/locss@1.0.1/dist/index.min.css">
    <meta name="referrer" content="no-referrer">
    <script src="https://cdn.jsdelivr.net/npm/@mxssfd/ts-utils@2.11.17/lib-umd/index.min.js"></script>
    <script src="https://img.bc.haodanku.com/cms/utils.v1_0_5.js"></script>
    <script defer>document.write('<link rel="stylesheet" href="https://img.bc.haodanku.com/cms/activity125.css?t=' + (Date.now() - Date.now() % (60 * 1000 * 30)) + '"/>')</script>
  </head>
  <body>
    <template id="c-share">
  <div class="footer-share">
    <div id="share_href" v-on:click="handleShare">
      <i>
        <svg xmlns="http://www.w3.org/2000/svg" id="svg-icon" data-name="图层 1" viewBox="0 0 18 19.11">
          <title>分享</title>
          <path class="cls-1" d="M17.5,8A2.5,2.5,0,1,0,15,5.5,2.5,2.5,0,0,0,17.5,8Z" transform="translate(-3 -2)"/>
          <path class="cls-1" d="M6.5,14.5A2.5,2.5,0,1,0,4,12,2.5,2.5,0,0,0,6.5,14.5Z" transform="translate(-3 -2)"/>
          <path class="cls-2" d="M15,6.79,8.67,10.62" transform="translate(-3 -2)"/>
          <path class="cls-2" d="M8.67,13.28,13.27,16" transform="translate(-3 -2)"/>
          <path class="cls-1" d="M15.77,15.11a2.5,2.5,0,1,1-2.5,2.5A2.5,2.5,0,0,1,15.77,15.11Z"
                transform="translate(-3 -2)"/>
        </svg>
      </i>
      <span>分享好友</span>
    </div>
  </div>
</template>
    <template id="c-list-item">
  <div class="goods-card">
    <div class="cover img-box">
      <img v-lazy="item.itempic" v-if="item.itempic"/>
      <img
        src="http://img.bc.fqapps.com/fudai13cae4ae6ef16739ed3b100a2ec39e97.gif"
        alt=""
        v-else
      />
      <div class="sale flex-c"><i class="iconfont hdk-huo"></i>日销量 {{getMoneyStr(item.itemsale2)}}</div>
    </div>
    <div class="detail">
      <div class="title">
        <img
          v-if="item.shoptype === 'B'"
          class="icon tm"
          src="http://img-haodanku-com.cdn.fudaiapp.com/FvU9Lg74-WgBzWQphv98-9KgYF6d"
          alt="">
        <img
          v-else-if="item.shoptype === 'C'"
          class="icon tb"
          src="http://img-haodanku-com.cdn.fudaiapp.com/FnCy1eY4W5khYdTw_iIDhKuwGLmu"
          alt="">
        <span>{{ item.itemshorttitle || item.itemtitle }}</span>
      </div>
      <div class="center" v-on:click.capture="buy($event, 'textCode')">
        <p>{{item.itemdesc}}</p>
      </div>
      <div class="price">
        <div class="end-price">
          券后价<strong>￥{{ Number(item.itemendprice) }}</strong>
        </div>
        <div class="origin">
          <del>￥{{ Number(item.itemprice) }}</del>
        </div>
      </div>
      <div class="tags">
        <div class="ticket" v-if="item.couponmoney != '0'">
          <span class="name">券</span><span class="value">￥{{ item.couponmoney }}</span>
        </div>
      </div>
      <div class="btn-block">
        <div class="btn-order">
          <span v-on:click.capture="buy">立即购买</span>
        </div>
      </div>
    </div>
  </div>
</template>

    <div id="single-page-app" v-cloak>
      <van-pull-refresh v-model="refreshing" @refresh="reGetListData">
        <van-list class="page-container" v-bind:loading="loading" v-bind:finished="listData.finished" v-on:load="getListData"><!-- 底部提示 -->
          <template #finished><span class="list-item-loading">-优惠到底啦-</span></template>
          <template #loading><span class="list-item-loading">数据正在赶来的路上...</span></template>
          <div class="banner-wrapper" ref="bannerRef"><img class="free-banner" v-bind:src="banner" alt=""></div>
          <van-sticky class="fixed-box" v-if="category.list.length&gt;1">
            <div class="category">
              <van-tabs class="scroll-nav" v-model:active="category.value" @click-tab="onNavChange" background="none">
                <van-tab v-for="item in category.list" v-bind:key="item.value" v-bind:name="item.value" v-bind:title="item.label"></van-tab>
              </van-tabs>
            </div>
          </van-sticky>
          <div class="page-content" ref="list" v-bind:class="{'empty-list':!listData.list.length}">
            <div class="lists">
              <template v-if="listData.list.length || listData.finished">
                <list-item v-for="(item, index) in listData.list" v-bind:item="item" v-bind:key="item.itemid" v-on:transfer-url="handleGoodsTransfer"></list-item>
              </template>
            </div>
          </div>
          <div class="back-top-wrap max-width">
            <div class="btn back-top" v-on:click="backTop" v-bind:class="{hide: scrollTop &lt; 600}"></div>
          </div>
          <share v-on:share="handleShare" v-bind:class="{hide:isScrollToDown}"></share>
          <van-overlay v-bind:show="loading">
            <van-loading color="#0094ff"></van-loading>
          </van-overlay>
        </van-list>
      </van-pull-refresh>
    </div>
    <script>
      function useBase() {
  const listDataStr = JSON.stringify({
    list: [],
    loading: false,
    finished: false,
    min_id: 1,
    pageTotal: 1,
    pageCurrent: 0
  });

  const scrollTop = Vue.ref(0);
  const listData = Vue.reactive(JSON.parse(listDataStr));

  // 根据微信浏览器缩放比例设置rem缩放
  if(inWechat() && "ontouchstart" in window) {
    const scale = getFontScale(true);
    document.documentElement.style.fontSize =
      "calc(100vw / 7.5 * " + scale + ")";
  }

  return {
    listDataStr,
    data: {
      scrollTop,
      listData
    },
    useScrollEndMounted(onScrollEnd, onNotScrollEnd) {
      Vue.onMounted(function() {
        window.addEventListener("scroll", function(ev) {
          scrollTop.value = document.documentElement.scrollTop || document.body.scrollTop;
          if(isScrollEnd(this, "vertical", 40)) {
            onScrollEnd && onScrollEnd();
          } else {
            onNotScrollEnd && onNotScrollEnd();
          }
        });
      });
    },
    methods: {
      onScrollEnd() {
        this.getListData();
      },
      handleShare() {
        copy(location.href, "复制成功，分享给身边好友吧~");
      },
      resetListData(isCleanList = true) {
        Object.assign(
          listData,
          JSON.parse(listDataStr),
          isCleanList ? undefined : {list: listData.list}
        );
      }
    }
  };
}

function findParent(component, parentName) {
  if(component.$options.name === parentName) {
    return component;
  }
  if(!component.$parent) return null;
  return findParent(component.$parent, parentName);
}window.onload = function() {
  const stamp = Date.now() - Date.now() % (60 * 1000 * 30);
  const ListItem = Vue.defineComponent({
    template: "#c-list-item",
    props: {
      item: Object
    },
    emits: ["transferUrl"],
    setup(props, ctx) {
      return {
        buy(e, type = "default") {
          ctx.emit("transferUrl", {e, item: props.item, type});
        },
        getMoneyStr(num) {
          const w = 10000;
          if(num < w) return num;
          return (num / w).toFixed(2) + "万";
        }
      };
    }
  });
  const Share = Vue.defineComponent({
    template: "#c-share",
    setup(props, ctx) {
      return {
        handleShare() {
          ctx.emit("share");
        }
      };
    }
  });
  const app = Vue.createApp({
    name: "App",
    components: {
      "list-item": ListItem,
      share: Share
    },
    setup() {
      const {data: baseData, methods: baseMethods, useScrollEndMounted} = useBase();
      const customParams = useCustomParams();
      const data = Object.assign(
        {},
        {
          banner: "https://img.bc.haodanku.com/cms/1635994050?t=" + stamp,
          top: 0,
          loading: Vue.ref(false),
          refreshing: Vue.ref(false),
          isScrollToDown: Vue.ref(false),
          category: Vue.reactive({
            value: "0",
            list: [],
            goodsLists: []
          })
        },
        baseData,
        customParams
      );
      Vue.watch(baseData.scrollTop, (n, o) => {
        data.isScrollToDown.value = n > o;
      });
      let methods = {
        onNavChange({name}) {
          data.listData.list = data.category.goodsLists[name];
        },
        backTop() {
          $("html,body").animate({scrollTop: 0});
        },
        backTopAndReGetListData() {
          methods.resetListData(false);
          $("html,body").animate({scrollTop: $(".banner-wrapper").height()});
          return methods.getListData(true);
        },
        reGetListData() {
          methods.resetListData(false);
          return methods.getListData(true);
        },

        /**
         * @return {Promise<any>}
         */
        async getListData() {
          const loading = data.loading;
          const listData = data.listData;
          if(loading.value || listData.loading || listData.finished) return Promise.reject();
          listData.loading = true;
          loading.value = true;
          const params = Object.assign(
            {id: 125},
            customParams.getListDataParams()
          );
          try {
            const res = await Request.get(url("www.tbpdd.top/api/hdk/get_index_activity_items"), params).promise;
            const block = res.data.block || [];
            data.category.list = block.map((item, index) => ({
              label: item.name,
              value: String(index)
            }));
            data.category.goodsLists = block.map(item => item.item);
            const list = data.category.goodsLists[0];
            setTimeout(() => {
              listData.list = list;
              listData.finished = true;
            }, 200);
            return res;
          } catch(e) {
            listData.list = [];
            listData.finished = true;
          } finally {
            setTimeout(() => {
              listData.loading = false;
              loading.value = false;
              data.refreshing.value = false;
            }, 200);
          }
        },
        /**
         * 商品转链
         * @param e {MouseEvent}
         * @param item
         * @param type {'default'|'textCode'}
         */
        async handleGoodsTransfer({e, item, type}) {
          const param = Object.assign({
            itemid: item.itemid,
            title: item.itemshorttitle || item.itemtitle,
            get_taoword: 1
          }, customParams.getTransferParams());

          function errorCB(res) {
            toast(res.msg || "转链失败");
          }

          const loading = data.loading;
          loading.value = true;
          try {
            await useResolveTransferResult(e.currentTarget, param, type, item);
          } catch(e) {
            errorCB(e);
          } finally {
            setTimeout(function() {
              loading.value = false;
            }, 200);
          }
        }
      };

      methods = Object.assign(baseMethods, methods);

      useScrollEndMounted();
      Vue.onMounted(() => methods.getListData(true));
      const computed = {};
      return Object.assign(data, methods, computed);
    }
  });
  app.use(vant);
  app.use(vant.Lazyload, {
    lazyComponent: true,
    preLoad: 1.3,
    error: "http://img.bc.haodanku.com/haodanku/1595237918",
    loading: "http://img.bc.fqapps.com/fudai13cae4ae6ef16739ed3b100a2ec39e97.gif",
    attempt: 1
  });
  app.mount("#single-page-app");
};
    </script>
    <script>
      function useCustomParams() {
        var customParams = {
          apikey: "sylar" //必填
        }
        return {
          commonParams: customParams,
          // 列表参数
          getListDataParams: function() {
            return customParams;
          },
          // 转链参数
          getTransferParams: function(item) {
            return Object.assign({
              pid: "mm_1520060136_2232550319_111181400478",//必填
              tb_name: "tb370655212",//必填
            }, customParams);
          }
        }
      }
      /**
       * 商品转链
       * @param el
       * @param param
       * @param item
       * @param type {'default'|'textCode'}
       */
      async function useResolveTransferResult(el,param, type, item) {
        const transferUrl = url("www.tbpdd.top/api/hdk/ratesurl");
        if(!inWechat()) {
          const res = await Request.post(transferUrl, param).promise;
          vant.Dialog.confirm({
            message: "是否跳转到下单页面?"
          }).then(() => {
            window.top.location = res.data.coupon_click_url || res.data.item_url;
          });
          return;
        }
      
        let copyText;
      
        const execCopy = () => {
          if(!copyText) return;
          copy(copyText, "复制口令成功,请打开淘宝领取", "复制失败,请点击重试", true);
        };
      
        el.addEventListener("click", function copyHandle() {
          execCopy();
          el.removeEventListener("click", copyHandle, false);
        }, false);
      
        return await Request.postSync(transferUrl, param, (res) => {
          const taocode = "0" + res.data.taoword + "/";
          copyText = ({
            default: taocode,
            textCode: '1' + item.itemdesc + taocode
          })[type];
        }).promise;
      }
    </script>
  </body>
</html>